package insterface_Demo_d5;
import java.util.ArrayList;
public class StudentOperatorImpl2 implements StudentOperator {
    //重写接口第二套方案
    @Override
    public void printAllInfo(ArrayList<Student> students) {
        System.out.println("-------全班全部信息如下-------");
        int man = 0; //统计男生人数
        int woman = 0; //统计女生人数
        //遍历学生数据
        for (int i = 0; i < students.size(); i++) {
            Student s = students.get(i);
            if (s.getSex() == '男') {
                man++;
            } else {
                woman ++;
            }
        }
        System.out.println("男士人数："+man +"女生人数："+woman);
        System.out.println("班级总人数："+students.size());
        System.out.println("---------------------------");
    }

    @Override
    public void printAvergeScore(ArrayList<Student> students) {
        double allscore = 0.0;
        double max = students.get(0).getScore();
        double min = students.get(0).getScore();
        for (int i = 0; i < students.size(); i++) {
            Student s = students.get(i);
            max = s.getScore()>max?s.getScore():max;
            min = s.getScore()<min?s.getScore():min;
            allscore += s.getScore();
        }
        System.out.println("学生最高分是："+max);
        System.out.println("学生最低分是："+min);
        System.out.println("平均分：" + (allscore-max-min) / (students.size()-2));
    }
}
